import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class GSYVideoPlayer extends StatelessWidget {
  const GSYVideoPlayer(
      {Key? key,
      required this.dataSource,
      required this.tag,
      required this.title})
      : super(key: key);
  final String dataSource;
  final String tag;
  final String title;
  @override
  Widget build(BuildContext context) {
    String viewType = 'karl_info'; // 唯一标识符
    var creationParams = {
      'type': 'info_view',
      // "dataSource":dataSource,
    }; // 视图创建参数，可以被插件用来传递构造函数参数到嵌入式Android视图
    // 视图创建完毕的回调
    PlatformViewCreatedCallback callback = (id) {
      print(id);
    };
    // 判断设备类型，也可用：defaultTargetPlatform == TargetPlatform.android
    if (Platform.isAndroid) {
      return AndroidView(
        viewType: viewType,
        onPlatformViewCreated: callback,
        creationParams: <String, dynamic>{
          ///给原生传递初始化参数 就是上面定义的初始化参数
          'dataSource': dataSource,
          'tag': tag,
          "title": title
        },

        /// 用来编码 creationParams 的形式，可选 [StandardMessageCodec], [JSONMessageCodec], [StringCodec], or [BinaryCodec]
        /// 如果存在 creationParams，则该值不能为null
        creationParamsCodec: const StandardMessageCodec(),
        // creationParams: creationParams,
      );
    } else if (Platform.isIOS) {
      return UiKitView(
        viewType: viewType,
        onPlatformViewCreated: callback,
      );
    } else {
      return Text('Platform is not yet supported by this plugin');
    }
  }
}
